<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = ["red", "green", "blue", "pink"];
      // 方法一
      var changeStr1 = arr.join(",");
      console.log(changeStr1);
      // 方法二
      var changeStr2 = arr.toString();
      console.log(changeStr2);
      // 方法三
      // result 累加器
      //current 当前值
      var changeStr3 = arr.reduce((result, current) => {
        // result ? "," : ""
        // 当有累计值时，用逗号拼接，目的是不让第一个元素前出现独逗号
        return result + (result ? "," : "") + current;
      }, "");

      console.log(changeStr3);
    </script>
  </body>
</html>
